// pages/communityCenterDetail/communityCenterDetail.js
var app = getApp();
Page({
  data: {
    centerId: '', // 社区中心ID
    centerInfo: {}, // 社区中心详情
    markers: [] // 地图标记点
  },

  onLoad(options) {
    this.setData({ centerId: options.id });
    this.loadCenterDetail();
  },

  // 加载社区中心详情
  loadCenterDetail() {
    wx.showLoading({ title: '加载中...' });
    const self = this;
    app.util.request({
    	url: 'Community/detail',
    	data: {
    		m: app.mdName,
    		id:this.data.centerId
    	},
    	success(res) {
    		const data = res.data.data;
			console.log(data)
			console.log('-----------------------')
			const centerInfo = {
				id: this.data.centerId,
				name: data.name,
				serviceHours: data.service_hours,
				phone: data.contact_phone,
				address: data.address,
				longitude: data.lng,
				latitude: data.lat,
				description: data.description,
				images: [
				  data.cover_image
				],
				
				staffList: [
				]
			  };
			  if(data.staff.length > 0){
				  data.staff.forEach(function(element) {
						centerInfo.staffList.push({
							id:element.id,
							name:element.name,
							title:element.title,
							avatar:element.avatar
						})
					});
			  }
			  self.setData({
				centerInfo,
				markers: [{
				  id: 0,
				  latitude: centerInfo.latitude,
				  longitude: centerInfo.longitude,
				  title: centerInfo.name,
				  iconPath: 'https://banyetang.oss-cn-beijing.aliyuncs.com/xiaochengxu/ic_address.png',
				  width: 30,
				  height: 30
				}]
			  });
    	}
    })
  },

  // 打开地图导航
  openMapNavigation() {
    const { latitude, longitude, name, address } = this.data.centerInfo;
    wx.openLocation({
      latitude,
      longitude,
      name,
      address,
      scale: 18
    });
  },

  // 拨打电话
  makePhoneCall() {
    const phone = this.data.centerInfo.phone;
    wx.makePhoneCall({
      phoneNumber: phone
    });
  },

  // 预约服务
  makeAppointment() {
    wx.navigateTo({
      url: `/pages/appointment/appointment?centerId=${this.data.centerId}`
    });
  },
});